<template>
	<div class="content">
		<div class="banse">
			<el-card class="box-card">
				<div slot="header" class="clearfix">
					<span>任务基础信息</span>
					<el-button style="float: right;margin-left: 10px;" type="primary" plain @click="go">返 回</el-button>
					<span v-if="power.includes('order_create_task')">
						<el-button style="float: right;" type="success" plain @click="editBtn" v-if="btnShow == 1">修 改</el-button>
						<el-button style="float: right;" type="success" plain @click="submit('form')" v-if="btnShow == 2">提 交</el-button>
					</span>
					<el-button @click="testReport" style="float: right;margin-right: 5px;" type="warning" v-if="form.gene_report == 0 && power.includes('report_gene')" plain>生成测试报告</el-button>
				</div>
				<div>
					<el-form ref="form" :rules="rules" :model="form" label-width="100px">
						<el-row :gutter="12">
							<el-col>
								<div style="display: flex;justify-content: space-between;">
									<el-form-item label="任务ID:">
										{{form.task_id}}
									</el-form-item>
									<el-form-item label="状态:">
										<el-button plain v-if="form.status == 0" type="primary">{{form.status_show}}</el-button>
										<el-button plain v-else-if="form.status == 1" type="success" >{{form.status_show}}</el-button>
										<el-button plain v-else-if="form.status == 2" type="warning" >{{form.status_show}}</el-button>
										<el-button plain v-else type="danger" >{{form.status_show}}</el-button>
<!--										{{form.status_show}}-->
									</el-form-item>
								</div>

							</el-col>
							<el-col :span="8">
								<el-form-item label="任务名称" prop="task_name">
									<el-input v-model="form.task_name" :disabled="btnShow == 1" placeholder="请输入任务名称"></el-input>
								</el-form-item>
								<el-form-item label="任务类型" prop="task_type">
									<el-select v-model="form.task_type" :disabled="btnShow == 1" placeholder="请选择任务类型" style="width:100%;" >
										<el-option
											v-for="item in tasktypeOptions"
											:key="item.index"
											:label="item.name"
											:value="item.name">
										</el-option>
									</el-select>
								</el-form-item>
								<el-form-item label="套件地址" prop="test_suite_url">
									<el-input v-model="form.test_suite_url" :disabled="btnShow == 1" placeholder="请输入套件地址"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="测试人员" prop="tester">
									<el-select v-model="form.tester" placeholder="请选择测试人员" multiple
											    style="width:100%;" value-key="id" :disabled="btnShow == 1">
										<el-option
											v-for="(item,index) in testerOptions"
											:key="index"
											:label="item.name"
											:value="item">
										</el-option>
									</el-select>
								</el-form-item>
								<el-form-item label="Android版本" prop="android_version">
									<el-input v-model="form.android_version" :disabled="btnShow == 1" placeholder="请输入Android版本"></el-input>
								</el-form-item>
								<el-form-item label="固件版本" prop="firmware_version">
									<el-input v-model="form.firmware_version" :disabled="btnShow == 1" placeholder="请输入固件版本"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="人力需求" prop="manpower">
									<el-input type="number" v-model="form.manpower" :disabled="btnShow == 1" :precision="2" :step="0.1" :min="0"
											  placeholder="请输入人力需求"></el-input>
								</el-form-item>

								<el-form-item label="ios版本" prop="ios_version">
									<el-input v-model="form.ios_version" :disabled="btnShow == 1" placeholder="请输入ios版本"></el-input>
								</el-form-item>
								<el-form-item label="插件版本" prop="unit_version">
									<el-input v-model="form.unit_version" :disabled="btnShow == 1" placeholder="请输入插件版本"></el-input>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col>
								<el-form-item label="测试区域" prop="remark">
									<el-input v-model="form.remark" :disabled="btnShow == 1" type="textarea" placeholder="请输入测试区域"></el-input>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col>
								<el-form-item label="任务时间" >
									<el-date-picker
										v-model="time"
										type="datetimerange"
										range-separator="至"
										start-placeholder="任务开始时间"
										end-placeholder="任务结束时间"
										style="width: 100%;"
										@change="dataChange"
										:disabled="btnShow == 1"
										align="right">
									</el-date-picker>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row v-if="btnShow == 1">
							<el-col>
								<el-form-item label="附件文档">
									<div v-for="(item,index) in form.doc" :key="index">
										<span @click="doc(item['id'])">文件名：<a :href="item['full_path']" >{{item['file_name']}}</a></span>
										<span style="margin: 0 20px;">下载次数：{{item['download_count']}}</span>
										<span v-if="!power.includes('order_create_task')"><el-button type="primary" size="small" @click="removeFlie(item['id'])">删除</el-button></span>
									</div>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row v-if="btnShow == 2">
							<el-col>
								<el-form-item label="附件文档">
									<el-upload
										class="upload-demo"
										action="string"
										:headers="headers"
										:http-request="uploadFile"
										:on-remove="deleteFile"
										:before-upload="beforeUpload">
										<el-button size="small" type="primary">附件上传</el-button>
									</el-upload>
									<div v-for="(item,index) in form.doc" :key="index">
										<span @click="doc(item['id'])">文件名：<a :href="item['full_path']" >{{item['file_name']}}</a></span>
										<span style="margin: 0 20px;">下载次数：{{item['download_count']}}</span>
										<span v-if="power.includes('order_create_task')"><el-button type="primary" size="small" @click="removeFlie(item['id'])">删除</el-button></span>
									</div>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
			</el-card>
		</div>
		<div class="order">
			<el-card class="box-card">
				<div slot="header" class="clearfix">
					<span>关联订单基本信息</span>
				</div>
				<div class="orderContent" @click="showOrder">
					<div class="item">基本信息(可展开)</div>
					<div class="item"><i class="el-icon-arrow-down"></i></div>

				</div>
				<div class="message" v-show="orderShow">
					<el-form ref="orderForm" :model="orderForm" label-width="0px">
						<el-row >
							<el-col :span="8">
								<el-form-item >
									MODEL：{{orderForm.project_name}}
								</el-form-item>
								<el-form-item label="">
									里程碑：{{orderForm.milepost}}
								</el-form-item>
								<el-form-item label="" >
									客户类型：{{orderForm.customer_type}}
								</el-form-item>
								<el-form-item label="" >
									状态：<el-tag :type="orderForm.status == 1?'success':(orderForm.status == 0?'warning':'danger')">{{orderForm.status_show}}</el-tag>
								</el-form-item>
								<el-form-item label="" >
									样机：<span v-for="(item,index) in orderForm.prototype" :key="index" style="margin: 0 5px;">
											<el-tag :type="item.length<=3?'success' : (item.length == 4 ? 'warning' : '')">{{item['name']}}</el-tag>
										</span>
								</el-form-item>
								<el-form-item label="" >
									品牌属性：{{orderForm.brand_type}}
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="">
									客户：{{orderForm.customer}}
								</el-form-item>
								<el-form-item label="">
									产品线：{{orderForm.product_line['name']}}
								</el-form-item>
								<el-form-item label="">
									产品：{{orderForm.product['name']}}
								</el-form-item>
								<el-form-item label="">
									创建人：{{orderForm.creator_show['name']}}
								</el-form-item>
								<el-form-item label="">
									销售区域：
									<span>
										<el-tag type="success">{{orderForm.sales_area || '暂无'}}</el-tag>
									</span>
								</el-form-item>

								<el-form-item label="" >
									联网方式：{{orderForm.networking_mode}}
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="">
									测试组：{{orderForm.group['name']}}
								</el-form-item>
								<el-form-item label="" >
									测试内容：<span v-for="(item,index) in getContent(orderForm.test_content)" :key="index" style="margin: 0 3px;">
												<el-tag :type="item.length<=3?'success' : (item.length == 4 ? 'warning' : '')">{{item}}</el-tag>
											</span>
								</el-form-item>
								<el-form-item label="" >
									创建时间：{{getTime(orderForm.create_time)}}
								</el-form-item>
								<el-form-item label="" >
									更新时间：{{getTime(orderForm.update_time)}}
								</el-form-item>
								<el-form-item label="" >
									计划时间：<span>{{ getJtime(orderForm.start_time) }}</span> ~ <span>{{ getJtime(orderForm.end_time) }}</span>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
			</el-card>
		</div>
		<div class="tab">
			<el-card class="box-card">
				<div slot="header" class="clearfix">
					<span>测试用例</span>
					<div style="float: right;">
						<el-popover
							placement="top"
							width="160"
							v-model="visible">
							<p>确定提交任务吗？</p>
							<div style="text-align: right; margin: 0">
								<el-button size="mini" type="text" @click="visible = false">取消</el-button>
								<el-button type="primary" size="mini" @click="testSubmit">确定</el-button>
							</div>
							<el-button type="primary" :disabled="!submitBtn" slot="reference">提交任务</el-button>
						</el-popover>
					</div>
					<div style="float: right;margin-right: 5px;">
						<el-button type="success" @click="down" slot="reference">导出结果</el-button>
					</div>
				</div>
				<el-tabs v-model="activeName" @tab-click="handleClick">
					<el-tab-pane label="IoT产品通用" name="first">
						<div class="caseLst">
							<div class="item">
								<div class="caseItem">
									<span>测试状态</span>
									<el-select v-model="status" clearable @change="search" placeholder="请选择状态">
										<el-option label="待测试" value="待测试"></el-option>
										<el-option label="测试完成" value="测试完成"></el-option>
									</el-select>
								</div>
								<div class="caseItem" style="margin: 0 5px;">
									<span>测试结果</span>
									<el-select v-model="result" clearable @change="search" placeholder="请选择状态">
										<el-option label="Pass" value="Pass"></el-option>
										<el-option label="Fail" value="Fail"></el-option>
										<el-option label="Block" value="Block"></el-option>
										<el-option label="Skip" value="Skip"></el-option>
										<el-option label="N/A" value="N/A"></el-option>
									</el-select>
								</div>

							</div>
							<div class="item">
								<div class="testTable">
									<el-table
										v-if="initTableList"
										class="marT"
										:data="initTableList"
										:border="true"
										:header-cell-style="{background:'#eef1f6'}"
										lazy
										v-loading="loading"
										row-key="case.id">
										<el-table-column align="center" type="index" label="序号" width="50">
										</el-table-column>
										<el-table-column align="center" property="case.case_name" label="用例标题" ></el-table-column>
										<el-table-column align="center" property="case.priority" label="优先级"></el-table-column>
										<el-table-column align="center" property="status_show" label="状态" >
											<template slot-scope="scope">
												<el-tag v-if="scope.row.status == 0">{{scope.row.status_show}}</el-tag>
												<el-tag v-else type="success">{{scope.row.status_show}}</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center"  label="测试人员" width="240">
											<template slot-scope="scope" >
												<span v-if="scope.row.test_time == null">-</span>
												<span v-if="scope.row.test_time != null">测试人员:{{getName(scope.row.tester_show)}}</span><br>
												<span v-if="scope.row.test_time != null">测试时间：{{getTime(scope.row.test_time)}}</span>
											</template>
										</el-table-column>
										<el-table-column align="center" property="result" label="测试结果">
											<template slot-scope="scope" >
												<el-tag :type="scope.row.result == 'Pass'?'success':'danger'" v-if="scope.row.result != null">{{scope.row.result}}</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center" property="remark" label="测试备注"
														 :show-overflow-tooltip="true">
										</el-table-column>
										<el-table-column align="center" property="tester_show" label="更新信息" >
											<template slot-scope="scope">
												<span>{{getName(scope.row.updated_by) }}</span><br>
												<span>{{getTime(scope.row.update_time) }}</span>
											</template>
										</el-table-column>
										<el-table-column align="center" label="操作" width="240">
											<template slot-scope="scope">
												<span><a @click="see(scope.row)" >查看</a></span>
												<span v-if="power.includes('test_case_del')"><a> | </a></span>
												<span v-if="power.includes('test_case_del')">
											<template>
												<el-popconfirm title="确认删除吗？" @confirm="del(scope.row)">
													<span slot="reference" class="del">删除</span>
												</el-popconfirm>
											</template>
										</span>
												<span><a> | </a></span>
												<span><a @click="edit(scope.row)" v-if="scope.row.status == 0" :disabled="!power.includes('task_result_input')">填写结果</a></span>
												<span><a @click="edit(scope.row)" v-if="scope.row.status == 1" :disabled="!power.includes('task_result_update')">修改结果</a></span>
												<span v-if="power.includes('bug_add')"><a> | </a></span>
												<span v-if="power.includes('bug_add')"><a @click="addBug(scope.row)" v-if="scope.row.is_commit_bug == 0">生成缺陷</a></span>
												<span v-if="power.includes('bug_add')"><a @click="seeBug(scope.row)" v-if="scope.row.is_commit_bug == 1">缺陷已提交</a></span>
											</template>
										</el-table-column>
									</el-table>
								</div>
							</div>
						</div>
					</el-tab-pane>
					<el-tab-pane label="品类通用" name="second">
						<div class="caseLst">
							<div class="item">
								<div class="caseItem">
									<span>测试状态</span>
									<el-select v-model="status" clearable @change="search" placeholder="请选择状态">
										<el-option label="待测试" value="待测试"></el-option>
										<el-option label="测试完成" value="测试完成"></el-option>
									</el-select>
								</div>
								<div class="caseItem" style="margin: 0 5px;">
									<span>测试结果</span>
									<el-select v-model="result" clearable @change="search" placeholder="请选择状态">
										<el-option label="Pass" value="Pass"></el-option>
										<el-option label="Fail" value="Fail"></el-option>
										<el-option label="Block" value="Block"></el-option>
										<el-option label="Skip" value="Skip"></el-option>
										<el-option label="N/A" value="N/A"></el-option>
									</el-select>
								</div>

							</div>
							<div class="item">
								<div class="testTable">
									<el-table
										v-if="commonList"
										class="marT"
										:data="commonList"
										:border="true"
										:header-cell-style="{background:'#eef1f6'}"
										lazy
										v-loading="loading"
										row-key="case.id">
										<el-table-column align="center" type="index" label="序号" width="50">
										</el-table-column>
										<el-table-column align="center" property="case.case_name" label="用例标题" ></el-table-column>
										<el-table-column align="center" property="case.priority" label="优先级"></el-table-column>
										<el-table-column align="center" property="status_show" label="状态" >
											<template slot-scope="scope">
												<el-tag v-if="scope.row.status == 0">{{scope.row.status_show}}</el-tag>
												<el-tag v-else type="success">{{scope.row.status_show}}</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center"  label="测试人员" width="240">
											<template slot-scope="scope" >
												<span v-if="scope.row.test_time == null">-</span>
												<span v-if="scope.row.test_time != null">测试人员:{{getName(scope.row.tester_show)}}</span><br>
												<span v-if="scope.row.test_time != null">测试时间：{{getTime(scope.row.test_time)}}</span>
											</template>
										</el-table-column>
										<el-table-column align="center" property="result" label="测试结果">
											<template slot-scope="scope" >
												<el-tag :type="scope.row.result == 'Pass'?'success':'danger'" v-if="scope.row.result != null">{{scope.row.result}}</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center" property="remark" label="测试备注"
														 :show-overflow-tooltip="true">
										</el-table-column>
										<el-table-column align="center" property="tester_show" label="更新信息" >
											<template slot-scope="scope">
												<span>{{getName(scope.row.updated_by) }}</span><br>
												<span>{{getTime(scope.row.update_time) }}</span>
											</template>
										</el-table-column>
										<el-table-column align="center" label="操作" width="240">
											<template slot-scope="scope">
												<span><a @click="see(scope.row)" >查看</a></span>
												<span v-if="power.includes('test_case_del')"><a> | </a></span>
												<span v-if="power.includes('test_case_del')">
											<template>
												<el-popconfirm title="确认删除吗？" @confirm="del(scope.row)">
													<span slot="reference" class="del">删除</span>
												</el-popconfirm>
											</template>
										</span>
												<span><a> | </a></span>
												<span><a @click="edit(scope.row)" v-if="scope.row.status == 0" :disabled="!power.includes('task_result_input')">填写结果</a></span>
												<span><a @click="edit(scope.row)" v-if="scope.row.status == 1" :disabled="!power.includes('task_result_update')">修改结果</a></span>
												<span v-if="power.includes('bug_add')"><a> | </a></span>
												<span v-if="power.includes('bug_add')"><a @click="addBug(scope.row)" v-if="scope.row.is_commit_bug == 0">生成缺陷</a></span>
												<span v-if="power.includes('bug_add')"><a @click="seeBug(scope.row)" v-if="scope.row.is_commit_bug == 1">缺陷已提交</a></span>
											</template>
										</el-table-column>
									</el-table>
								</div>
							</div>
						</div>
					</el-tab-pane>
					<el-tab-pane label="品类特有" name="third">
						<div class="caseLst">
							<div class="item">
								<div class="caseItem">
									<span>测试状态</span>
									<el-select v-model="status" clearable @change="search" placeholder="请选择状态">
										<el-option label="待测试" value="待测试"></el-option>
										<el-option label="测试完成" value="测试完成"></el-option>
									</el-select>
								</div>
								<div class="caseItem" style="margin: 0 5px;">
									<span>测试结果</span>
									<el-select v-model="result" clearable @change="search" placeholder="请选择状态">
										<el-option label="Pass" value="Pass"></el-option>
										<el-option label="Fail" value="Fail"></el-option>
										<el-option label="Block" value="Block"></el-option>
										<el-option label="Skip" value="Skip"></el-option>
										<el-option label="N/A" value="N/A"></el-option>
									</el-select>
								</div>

							</div>
							<div class="item">
								<div class="testTable">
									<el-table
										v-if="specificList"
										class="marT"
										:data="specificList"
										:border="true"
										:header-cell-style="{background:'#eef1f6'}"
										lazy
										v-loading="loading"
										row-key="case.">
										<el-table-column align="center" type="index" label="序号" width="50">
										</el-table-column>
										<el-table-column align="center" property="case.case_name" label="用例标题" ></el-table-column>
										<el-table-column align="center" property="case.priority" label="优先级"></el-table-column>
										<el-table-column align="center" property="status_show" label="状态" >
											<template slot-scope="scope">
												<el-tag v-if="scope.row.status == 0">{{scope.row.status_show}}</el-tag>
												<el-tag v-else type="success">{{scope.row.status_show}}</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center"  label="测试人员" width="240">
											<template slot-scope="scope" >
												<span v-if="scope.row.test_time == null">-</span>
												<span v-if="scope.row.test_time != null">测试人员:{{getName(scope.row.tester_show)}}</span><br>
												<span v-if="scope.row.test_time != null">测试时间：{{getTime(scope.row.test_time)}}</span>
											</template>
										</el-table-column>
										<el-table-column align="center" property="result" label="测试结果">
											<template slot-scope="scope" >
												<el-tag :type="scope.row.result == 'Pass'?'success':'danger'" v-if="scope.row.result != null">{{scope.row.result}}</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center" property="remark" label="测试备注"
														 :show-overflow-tooltip="true">
										</el-table-column>
										<el-table-column align="center" property="tester_show" label="更新信息" >
											<template slot-scope="scope">
												<span>{{getName(scope.row.updated_by) }}</span><br>
												<span>{{getTime(scope.row.update_time) }}</span>
											</template>
										</el-table-column>
										<el-table-column align="center" label="操作" width="240">
											<template slot-scope="scope">
												<span><a @click="see(scope.row)" >查看</a></span>
												<span v-if="power.includes('test_case_del')"><a> | </a></span>
												<span v-if="power.includes('test_case_del')">
											<template>
												<el-popconfirm title="确认删除吗？" @confirm="del(scope.row)">
													<span slot="reference" class="del">删除</span>
												</el-popconfirm>
											</template>
										</span>
												<span><a> | </a></span>
												<span><a @click="edit(scope.row)" v-if="scope.row.status == 0" :disabled="!power.includes('task_result_input')">填写结果</a></span>
												<span><a @click="edit(scope.row)" v-if="scope.row.status == 1" :disabled="!power.includes('task_result_update')">修改结果</a></span>
												<span v-if="power.includes('bug_add')"><a> | </a></span>
												<span v-if="power.includes('bug_add')"><a @click="addBug(scope.row)" v-if="scope.row.is_commit_bug == 0">生成缺陷</a></span>
												<span v-if="power.includes('bug_add')"><a @click="seeBug(scope.row)" v-if="scope.row.is_commit_bug == 1">缺陷已提交</a></span>
											</template>
										</el-table-column>
									</el-table>
								</div>
							</div>
						</div>
					</el-tab-pane>
				</el-tabs>
			</el-card>
		</div>
		<resultForm ref="resultForm" @func="test"></resultForm>
		<seeTask ref="seeTask" @func="test"></seeTask>
		<bugForm ref="bugForm" @func="test"></bugForm>
		<seeForm ref="seeForm"></seeForm>
	</div>
</template>

<script>
import { taskId, orderDetail, taskDoc, taskdocDelete,taskCase,orderOptions,groupId,taskIdPost,
	taskSubmit, orderIdCase, caseDownload} from '@/api/user'
import { getHeaderName } from '@/app.config'
import resultForm from "./model/resultForm";
import seeTask from "./model/seeTask";
import bugForm from "./model/bugForm";
import seeForm from "../bugAdmin/model/seeForm";
import moment from "moment";
import axios from "axios";
export default {
	name:'detail',
	components:{
		resultForm,
		seeTask,
		bugForm,
		seeForm
	},
	data(){
		return {
			commonType:'iot_common',
			activeName:'first',
			visible:false,
			submitBtn:false,
			btnShow:1,
			headers:{'Content-Type':'multipart/form-data'},
			status:'',
			result:'',
			form:{},
			num:'',
			rules:{
				task_name:[
					{max: 50, message: '任务名称不能超过50个字符', trigger: 'blur'},
					{required: true, message: '请输入任务名称', trigger: 'blur'}
					],
				android_version:[{max: 36, message: 'Android版本不能超过36个字符', trigger: 'blur'}],
				ios_version:[{max: 36, message: 'ios版本不能超过36个字符', trigger: 'blur'}],
				unit_version:[{max: 36, message: '插件版本不能超过36个字符', trigger: 'blur'}],
				firmware_version:[{max: 36, message: '固件版本不能超过36个字符', trigger: 'blur'}],
				test_suite_url:[{max: 150, message: '套件地址不能超过150个字符', trigger: 'blur'}],
				remark:[{max: 100, message: '测试区域不能超过100个字符', trigger: 'blur'}],
				task_type:{required: true, message: '请选择任务类型', trigger: 'change' },
				tester: [{ required: true, message: '请选择测试人员', trigger: 'change' }],
				manpower:[
					{required: true, message: '请输入人力需求', trigger: 'change'}
				]
			},
			tableData:[],

			initTableList:[], //  IoT产品通用用例列表
			initTableListspare:[],
			commonList:[],    //  品类通用用例列表
			commonListspare:[],
			specificList:[],  //  品类特有用例列表
			specificListspare:[],

			searchData:[],
			testerOptions:[],
			tasktypeOptions:[],
			power:[],
			// 控制订单信息展示
			orderShow:false,
			// 订单信息
			orderForm:{
				product_line:{name:''},
				product:{name:''},
				creator_show:{name:''},
				group:{name:''},
				test_content:[],
				server:[]
			},
			loading:false,
			time:[],
			fileList:[],
			arr:[],
		}
	},
	created() {
		this.id = this.$route.params.id

		this.initData(this.$route.params.id)
	},
	methods:{
		// 下载测试用例结果
		down() {
			let path = `${process.env.VUE_APP_KANBAN_HOST}/api/v1/task/${this.id}/case/download`
			axios.get(path,{
				responseType: 'blob',
				headers: getHeaderName()
			}).then(res => {
				if(res.status === 200) {
					const blob = new Blob([res.data]);
					const fileName = `task_case(${this.form.task_name}).xls`;
					// for IE
					if (window.navigator && window.navigator.msSaveOrOpenBlob) {
						window.navigator.msSaveOrOpenBlob(blob, fileName)
					} else {
						// for Non-IE (chrome, firefox etc.)
						const elink = document.createElement('a');
						elink.download = fileName;
						elink.style.display = 'none';
						elink.href = URL.createObjectURL(blob);
						document.body.appendChild(elink);
						elink.click();
						URL.revokeObjectURL(elink.href);
						document.body.removeChild(elink);
						this.loading = false
						this.$message({
							type:"success",
							message:"导出成功!"
						})
					}
				} else {
					this.loading = false
					this.$message.error('下载出错了!');
				}
			}).catch((err) => {
				console.log(err.message);
			});
		},
		//切换用例标签页
		handleClick(){
			if(this.activeName == 'first'){
				this.commonType = 'iot_common'
			}
			if(this.activeName == 'second'){
				this.commonType = 'common'
			}
			if(this.activeName == 'third'){
				this.commonType = 'specific'
			}
			this.search()
		},
		// 生成测试报告
		testReport(){
			this.$router.push(`/testingreport/${this.id}/1`)
		},
		// 提交任务
		testSubmit(){
			taskSubmit(this.id).then(res => {
				if(res.status == 'success'){
					this.$message.success(res.message)
				}else {
					this.$message.error(res.message)
				}
			})
			this.visible = false
		},

		// 提交修改
		submit(form){
			this.$refs[form].validate((valid) => {
				if(valid){
					let testerList = []
					this.form.tester.forEach(item => {
						testerList.push(item['id'])
					})

					this.arr.forEach(item => {
						this.fileList.push(item['fileKey'])
					})
					let data = {
						task_name:this.form.task_name,
						task_type:this.form.task_type,
						tester:testerList,
						manpower:this.form.manpower,
						ios_version:this.form.ios_version,
						android_version:this.form.android_version,
						unit_version:this.form.unit_version,
						firmware_version:this.form.firmware_version,
						test_suite_url:this.form.test_suite_url,
						remark:this.form.remark,
						doc:this.fileList,
						start_time:this.form.start_time,
						end_time:this.form.end_time
					}
					taskIdPost(data,this.form.id).then(res => {
						if(res.status == 'success'){
							this.$message.success(res.message)
							this.initData(this.id)
						}else {
							this.$message.error(res.message)
							this.initData(this.id)
						}
						this.btnShow = 1
					})
				}
			})
		},
		// 任务时间事件
		dataChange(e){
			this.form.start_time = e[0]
			this.form.end_time = e[1]
		},
		// 删除用例
		del(data){
			taskCase(data.id).then(res => {
				if(res.status == 'success'){
					this.$message.success('删除成功！')
					this.initData(this.id)
				}else {
					this.$message.error('删除失败！')
				}
			})
		},
		doc(data){
			taskDoc(data).then(response => {
			}).then(response => {
				this.initData(this.id)
			})
		},
		removeFlie(data){
			this.arr.forEach((item,index) => {
				if(item['id'] == data){
					if(this.arr.length > 0){
						this.arr.splice(index,1)
					}
					if(this.arr.length == 1){
						if(index == 0){
							this.arr = []
						}
					}
				}
			})
			taskdocDelete(data).then(response => {
				if(response.status == 'success'){
					this.$message.success('删除成功！')
					this.initData(this.id)
				}

			})
		},
		deleteFile(file, fileList) {
			let fileArr = this.form.doc
			this.$message.success("成功移除!")
			this.form.doc.forEach(item => {
				var arr = item.split('/')
				if(file.name == arr[arr.length-1] ){
					console.log(arr[arr.length-1])
				}
			})
		},
		beforeUpload(file){
			var type = file.name
			type = type.split('.')[1]
		},
		//上传附件
		uploadFile(file) {
			let url= `${process.env.VUE_APP_KANBAN_HOST}/api/v1/file`
			let fd = new FormData();
			fd.append('file',file.file);
			axios({
				url:url,
				data: fd,
				method:'post',
			}).then(res => {
				if(res.data.code === 200) {
					this.$message.success("上传成功!")
					this.fileList.push(res.data.data.key)
				}
			})
		},
		getJtime(data){
			let time = moment(data).format('YYYY-MM-DD HH:mm:ss')
			return time
		},
		// 控制订单信息展示
		showOrder(){
			this.orderShow = !this.orderShow
		},
		getContent(data){
			let name = []
			data.filter((item,index) => {
				name.push(item['test_content'])
			})
			return name
		},
		getServer(data){
			let name = []
			data.forEach((item,index) => {
				name.push(item['server'])
			})
			return name
		},
		// 备注
		stateFormat(row, column, cellValue){
			if(!cellValue){
				return '-'
			}
			if( cellValue.length > 10 ){
				return cellValue.slice(0, 10) + '...'
			}
			return cellValue
		},
		// 搜索测试用例
		search(){
			if(this.commonType == 'iot_common'){
				this.initTableList = []
				if(this.result == ''){
					this.initTableListspare.filter(item => {
						if(item['status_show'] == this.status){
							this.initTableList.push(item)
						}
					})
				}
				if(this.status == ''){
					this.initTableListspare.filter(item => {
						if(item['result'] == this.result){
							this.initTableList.push(item)
						}
					})
				}
				if(this.result != '' && this.status != ''){
					this.initTableListspare.filter(item => {
						if(item['result'] == this.result && item['status_show'] == this.status){
							this.initTableList.push(item)
						}
					})
				}
				if(this.result == '' && this.status == ''){
					this.initTableList = this.initTableListspare
				}
			}
			if(this.commonType == 'common'){
				this.commonList = []
				if(this.result == ''){
					this.commonListspare.filter(item => {
						if(item['status_show'] == this.status){
							this.commonList.push(item)
						}
					})
				}
				if(this.status == ''){
					this.commonListspare.filter(item => {
						if(item['result'] == this.result){
							this.commonList.push(item)
						}
					})
				}
				if(this.result != '' && this.status != ''){
					this.commonListspare.filter(item => {
						if(item['result'] == this.result && item['status_show'] == this.status){
							this.commonList.push(item)
						}
					})
				}
				if(this.result == '' && this.status == ''){
					this.commonList = this.commonListspare
				}
			}
			if(this.commonType == 'specific'){
				this.specificList = []
				if(this.result == ''){
					this.specificListspare.filter(item => {
						if(item['status_show'] == this.status){
							this.specificList.push(item)
						}
					})
				}
				if(this.status == ''){
					this.specificListspare.filter(item => {
						if(item['result'] == this.result){
							this.specificList.push(item)
						}
					})
				}
				if(this.result != '' && this.status != ''){
					this.specificListspare.filter(item => {
						if(item['result'] == this.result && item['status_show'] == this.status){
							this.specificList.push(item)
						}
					})
				}
				if(this.result == '' && this.status == ''){
					this.specificList = this.specificListspare
				}
			}
		},
		go(){
			this.$router.go(-1)
		},
		editBtn(){
			this.btnShow = 2
			this.$message.warning('您可以修改数据了，请填写完点击提交！')
		},
		test(data){
			let iot_common = []
			let common = []
			let specific = []

			taskId(data).then(res => {
				res.data.task_case.forEach(item => {
					if(item.case['type'] == 'common'){
						common.push(item)
					}
					if(item.case['type'] == 'iot_common'){
						iot_common.push(item)
					}
					if(item.case['type'] == 'specific'){
						specific.push(item)
					}
				})
				this.$nextTick(() => {
					this.initTableList = iot_common  //  IoT产品通用用例列表
					this.initTableListspare = iot_common
					this.commonList = common    //  品类通用用例列表
					this.commonListspare = common
					this.specificList = specific  //  品类特有用例列表
					this.specificListspare = specific
				})

				// this.tableData = res.data.task_case
				// this.searchData = res.data.task_case
				this.submitBtn = res.data.can_submit
				this.form = Object.assign({},res.data)
			}).then(res => {
				this.search()
			})
		},
		// 测试组里的组员
		testPerson(argm){
			groupId(argm).then(res => {
				this.testerOptions = res.data.tester
			})
		},
		initData(data){
			let iot_common = []
			let common = []
			let specific = []

			this.num = 3
			this.power = sessionStorage.getItem('power').split(',')

			this.id = data

			taskId(data).then(res => {
				this.submitBtn = res.data.can_submit
				this.time = []
				this.time.push(this.getTime(res.data.start_time),this.getTime(res.data.end_time))

				res.data.doc.forEach(item => {
					this.arr.push({'id':item['id'],'fileKey':item['file_key']})
				})

				// 订单信息
				orderDetail(res.data.order_id).then(res => {
					this.orderForm = Object.assign({},res.data)
					this.testPerson(this.orderForm.group['id'])
				})

				res.data.task_case.forEach(item => {
					if(item.case['type'] == 'common'){
						common.push(item)
					}
					if(item.case['type'] == 'iot_common'){
						iot_common.push(item)
					}
					if(item.case['type'] == 'specific'){
						specific.push(item)
					}
				})
				this.initTableList = iot_common  //  IoT产品通用用例列表
				this.initTableListspare = iot_common
				this.commonList = common    //  品类通用用例列表
				this.commonListspare = common
				this.specificList = specific  //  品类特有用例列表
				this.specificListspare = specific


				this.searchData = res.data.task_case

				this.form = Object.assign({},res.data)
			})

			orderOptions().then(res => {
				var data = res.data
				data.test_types.forEach(item => {
					this.tasktypeOptions.push({name:item})
				})

			})
		},
		see(data){
			this.$refs.seeTask.taskListVisible = true
			this.$refs.seeTask.initData(data,this.id)
		},
		edit(data){
			this.$refs.resultForm.dialogFormVisible = true
			this.$refs.resultForm.initData(data,this.id)
		},
		addBug(data){
			this.$refs.bugForm.dialogFormVisible = true
			this.$refs.bugForm.initData(1,data,this.orderForm,this.id)
		},
		seeBug(data){
			// this.$refs.seeForm.dialogFormVisible = true
			// this.$refs.seeForm.initId(data)
			this.$router.push(`/bugDetail/${data.bug_id}`)
		},
		getTime(data){
			if(data != null){
				var d = new Date(data);
				var d2 = d.getTime() - 8 * 60 * 60 * 1000
				d = new Date(d2)
				var  resDate = d.getFullYear() + '-' +
					((d.getMonth() + 1)<10?'0'+(d.getMonth() + 1):(d.getMonth() + 1)) + '-' +
					(d.getDate()<10?'0'+d.getDate():d.getDate())+ ' '+
					(d.getHours()<10?'0'+d.getHours():d.getHours())+':'+
					(d.getMinutes()<10?'0'+d.getMinutes():d.getMinutes())+':'+
					(d.getSeconds()<10?'0'+d.getSeconds():d.getSeconds());
				return resDate
			}else {
				return '暂无'
			}
		},
		getName(data){
			if(data){
				return data['name']
			}else {
				return '暂无'
			}
		}
	}
}
</script>


<style lang="scss" scoped>
.content{
	padding: 0 10px;
	margin-bottom: 50px;
	min-height: 1000px;
}
.banse{
	margin-top: 10px;
}
.testTable{
	height: 430px;
	overflow:scroll;
}
.order{
	margin-top: 15px;
}
.order .orderContent{
	display: flex;
	justify-content: space-between;
	width: 100%;
	background-color: #eee;
	padding: 8px;
	cursor: pointer;
}
.order .message{
	margin-top: 5px;
}
.tab{
	margin: 15px 0;
}
.caseLst .item:first-child{
	display: flex;
	margin-bottom: 15px;
}
.del{
	color: #1890FF;
	cursor: pointer;
}
</style>
